package com.ruoyi.ihome.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.annotation.JsonSetter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ihome.domain.IhHome;
import com.ruoyi.ihome.service.IIhHomeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 房间信息Controller
 *
 * @author NING
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/ihome/home")
public class IhHomeController extends BaseController {
    @Autowired
    private IIhHomeService ihHomeService;

    /**
     * 查询房间信息列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:list')")
    @GetMapping("/list")
    public TableDataInfo list(IhHome ihHome) {
        startPage();
        List<IhHome> list = ihHomeService.selectIhHomeList(ihHome);
//        List<IhHome> list = ihHomeService.selectAllBylandorder(ihHome);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('ihome:home:list')")
    @GetMapping("/house")
    public TableDataInfo house(IhHome ihHome) {
        startPage();
        List<IhHome> list = ihHomeService.selectIhHome(ihHome);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('ihome:home:list')")
    @GetMapping("/landorder/{id}")
    public AjaxResult selectAllBylandorder(@PathVariable("id")Long id) {
        return success(ihHomeService.selectAllBylandorder(id));
    }

    /**
     * 导出房间信息列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:export')")
    @Log(title = "房间信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IhHome ihHome) {
        List<IhHome> list = ihHomeService.selectIhHomeList(ihHome);
        ExcelUtil<IhHome> util = new ExcelUtil<IhHome>(IhHome.class);
        util.exportExcel(response, list, "房间信息数据");
    }


    /**
     * 获取房间信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ihHomeService.selectIhHomeById(id));
    }

    /**
     * 新增房间信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:add')")
    @Log(title = "房间信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IhHome home)
    {
        return ihHomeService.insertIhHome(home)==0?AjaxResult.error("用户尚未实名认证"):toAjax(ihHomeService.insertIhHome(home));
    }

    /**
     * 修改房间信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:edit')")
    @Log(title = "房间信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IhHome ihHome) {
        return toAjax(ihHomeService.updateIhHome(ihHome));
    }

    /**
     * 删除房间信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:remove')")
    @Log(title = "房间信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ihHomeService.deleteIhHomeByIds(ids));
    }
}
